package com.feidee.fd.sml.algorithm.feature

import com.feidee.fd.sml.algorithm.component.feature.{VectorSliceEncoder, VectorSliceEncoderParam}
import com.feidee.fd.sml.algorithm.util.{TestingDataGenerator, ToolClass}
import org.scalatest.FunSuite

/**
  * @Author: dongguosheng
  * @Date: 2019/3/22 16:15
  * @Review songhaicheng
  * @Email: guosheng_dong@sui.com
  */
class VectorSliceEncoderSuite  extends FunSuite {
  val paramStr: String =
    """
      |{
      |	"inputCol": "userFeatures",
      | "outputCol": "features",
      |	"features": "features",
      |	"numTopFeatures": 50,
      | "labelCol": "id",
      |	"indices": [1],
      |	"names": ["f3"]
      |}
    """.stripMargin

  val vectorSlicer = new VectorSliceEncoder()
  val param: VectorSliceEncoderParam = vectorSlicer.parseParam(new ToolClass().encrypt(paramStr))

  test("VectorSlicerEncoder parameter construction test") {
    assert(param.input_pt == null && param.output_pt == null &&
      "userFeatures".equals(param.inputCol) && "features".equals(param.outputCol)
      && param.indices.length > 0 && param.names.length > 0
    )
  }

  test("VectorSlicerEncoder training function test") {
    val testingData = TestingDataGenerator.makeVectorSlicerData()
    vectorSlicer.train(param, testingData).transform(testingData).show()
  }
}
